/**
 * Copyright 2016-2017 TVI Go Easy.
 * Created on 2017/4/17 22:48
 */
package org.mechanic.fund.web.product;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.mechanic.core.web.MediaTypes;
import org.mechanic.fund.domain.product.ProductType;
import org.mechanic.fund.service.product.IProductTypeService;
import org.mechanic.fund.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 产品系列 API
 *
 * @author mechanic
 * @version 0.0.1
 */
@Api(value = "产品系列接口")
@RestController
@RequestMapping(value = "product/type")
public class ProductTypeController extends BaseController {
    private final IProductTypeService typeService;

    @Autowired
    public ProductTypeController(IProductTypeService typeService) {
        this.typeService = typeService;
    }

    @ApiOperation(value = "返回所有产品系列列表")
    @RequestMapping(value = "list", method = RequestMethod.GET, produces = MediaTypes.JSON_UTF_8)
    public Object getProductTypeList() {
        List<ProductType> types = this.typeService.getProductTypeList();
        return result(types);
    }

    @ApiOperation(value = "批量保存产品系列")
    @RequestMapping(value = "save", method = RequestMethod.PUT, produces = MediaTypes.JSON_UTF_8, consumes = MediaTypes.JSON_UTF_8)
    public Object save(
      @ApiParam(value = "产品系列集合", required = true) @RequestBody(required = true)
        List<ProductType> productTypes) {
        this.typeService.save(productTypes,super.currUser().getId());
        return result();
    }

    @ApiOperation(value = "按 ID 删除产品系列")
    @RequestMapping(value = "delete/{id}", method = RequestMethod.DELETE, produces = MediaTypes.JSON_UTF_8)
    public Object delete(
      @ApiParam(value = "产品系列 ID", required = true) @PathVariable(required = true) String id) {
        this.typeService.delete(id);
        return result();
    }
}
